package com.sdgs.paas.sdk.core.config;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

import com.sdgs.paas.sdk.core.web.client.PaasRestTemplate;

/**
 * 从配置中心拉取纯文本配置文件服务
 * 
 * @author wjj
 * 
 */
public class PaasPlainConfigFileService implements IPaasPlainConfigFileService {
	@Autowired
	PaasPlainConfigFileProperties config;

	@Autowired
	PaasRestTemplate restTemplate;

	@Override
	public InputStream getPlainConfigFile(String app, String profile, String label, String FileName) {
		String url = new StringBuilder("http://").append(config.getConfigserver()).append("/").append(app).append("/")
				.append(profile).append("/").append(label).append("/").append(FileName).toString();
		ResponseEntity<byte[]> response = restTemplate.getForEntity(url, byte[].class);

		byte[] result = response.getBody();

		InputStream inputStream = new ByteArrayInputStream(result);
		return inputStream;
	}
}
